var uInfor = {
    inited: false,
    init: function(){
        // 员工数据对象
        var staffMeta = [{
            desc: '员工ID',
            field: 'staffId',
            xtype: 'hidden'
        }, {
            field: 'staffName',
            desc: '员工姓名',
            obj: {
                allowBlank: false
            }
        }, {
            field: 'sex',
            desc: '性别',
            xtype: 'acombo',
            obj: {
                ds: {
                    data: [[0, '未知'], [1, '男'], [2, '女']],
                    fields: ['key', 'label']
                },
                value: 0
            }
        }, {
            field: 'placeId',
            desc: '职位',
            xtype: 'hidden'
        }, {
            field: 'age',
            desc: '年龄'
        }, {
            field: 'birthday',
            desc: '生日',
            xtype: 'date'
        }, {
            field: 'cardNo',
            desc: '证件号码'
        }, {
            field: 'companyId',
            desc: '所属分公司',
            xtype: 'hidden'
        }, {
            field: 'departId',
            desc: '所属部门',
            xtype: 'hidden'
        }, {
            field: 'relaPhone',
            desc: '联系电话'
        }, {
            field: 'relaMobile',
            desc: '移动电话'
        }, {
            field: 'sendPhone',
            desc: '短信小灵通'
        }, {
            field: 'sendMobile',
            desc: '短信手机'
        }, {
            field: 'faxPhone',
            desc: '传真'
        }, {
            field: 'otherRelaPhone',
            desc: '其他联系电话'
        }, {
            field: 'relaAddr',
            desc: '联系地址'
        }, {
            field: 'email',
            desc: 'EMAIL',
            vtype: 'email'
        }];
        
        // 员工信息维护窗口
        this.staffWin = new CQCIS.form.WinForm({
            title: '员工信息',
            width: 400,
            height: 420,
            items: new CQCIS.form.DWRForm({
                dwr: {
                    load: staffDwr.getStaff,
                    update: staffDwr.updateInfo
                },
                metas: staffMeta,
                listeners: {
                    'saveafter': function(msg){
                        CQCIS.msg("操作成功");
                    }
                }
            })
        });
        
        // 密码修改窗口
        this.pwdWin = new CQCIS.form.WinForm({
            title: '修改密码',
            width: 260,
            height: 130,
            resizable: false,
            keys: [{
                key: Ext.EventObject.ENTER,
                fn: function(){
                    CQCIS.confirm('你确认要保存吗？', function(arg){
                        if (arg == 'yes') {
                            uInfor.pwdWin.save();
                        }
                    }, uInfor.pwdWin);
                }
            }, {
                key: Ext.EventObject.ESC,
                fn: function(o, e){
                    e.stopEvent();
                    if (uInfor.pwdWin.isClosable) {
                        uInfor.pwdWin.hide();
                    } else {
                        uInfor.pwdWin.show.defer(1, uInfor.pwdWin);
                    }
                }
            }],
            items: new CQCIS.form.DWRForm({
                labelWidth: 60,
                dwr: {
                    save: function(){
                        authDwr.doChangePassword(uInfor.pwdWin.form.findField('pwd').getValue(), function(){
                            uInfor.pwdWin.form.afterRemote();
                            uInfor.pwdWin.hide();
                            CQCIS.msg("密码修改成功");
                        });
                    }
                },
                metas: [{
                    field: 'pwd',
                    desc: '密　　码',
                    xtype: 'pwd',
                    obj: {
                        anchor: '92%',
                        allowBlank: false,
                        validator: function(val){
                            var flag;
                            authDwr.isPwdChg(val, {
                                async: false,
                                callback: function(effective){
                                    flag = effective;
                                }
                            });
                            return flag ? true : '输入的密码与最近使用过的5次相同！';
                        }
                    }
                }, {
                    field: 'repwd',
                    desc: '重复密码',
                    xtype: 'pwd',
                    obj: {
                        anchor: '92%',
                        allowBlank: false,
                        validator: function(val){
                            if (val != uInfor.pwdWin.form.findField('pwd').getValue()) {
                                return '两次输入的密码不一致！';
                            } else {
                                return true;
                            }
                        }
                    }
                }],
                listeners: {
                    'saveafter': function(msg){
                        CQCIS.msg("操作成功");
                    }
                }
            }),
            listeners: {
                'show': function(o){
                    if (o.isClosable) {
                        o.buttons[1].enable();
                        o.header.down('.x-tool-close').show();
                    } else {
                        o.buttons[1].disable();
                        o.header.down('.x-tool-close').hide();
                    }
                }
            }
        });
        
        this.inited = true;
    },
    modiInfo: function(){
        if (!this.inited) {
            this.init();
        }
        this.staffWin.load(CURRENTUSER.staffId);
    },
    modiPWD: function(){
        if (!this.inited) {
            this.init();
        }
        this.pwdWin.isClosable = true;
        this.pwdWin.load();
    },
    initPWD: function(){
        if (!this.inited) {
            this.init();
        }
        this.pwdWin.isClosable = false;
        this.pwdWin.load();
    }
};

function checkPWD(){
    var form = uInfor.pwdWin.form;
    var lastPwd = form.findField("lastPwd").getValue();
    var loginPwd = form.findField("loginPwd").getValue();
    var repwd = form.findField("_repwd").getValue();
    return loginPwd == repwd ? true : "两次输入的新密码不一致,请检查！";
    return loginPwd == lastPwd ? true : "旧密码和新密码不能一致,请检查！";
}

function checkPassword(){

    var form = uInfor.passwordWin.form;
    var lastPwd = form.findField("lastPwd").getValue();
    var loginPwd = form.findField("loginPwd").getValue();
    var repwd = form.findField("_repwd").getValue();
    
    return loginPwd == repwd ? true : "两次输入的新密码不一致,请检查！";
    return loginPwd == lastPwd ? true : "旧密码和新密码不能一致,请检查！";
}
